package com.kvest.mobile_newspaper.android;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.kvest.mobile_newspaper.R;
import com.kvest.mobile_newspaper.datamodel.Element;

public class FavoriteListAdapter extends ArrayAdapter<Element>
{
	private ArrayList<Element> items;
	private LayoutInflater inflater;
	
	public FavoriteListAdapter(Context context, int textViewResourceId, ArrayList<Element> items) 
    {
        super(context, textViewResourceId, items);
        this.inflater = LayoutInflater.from(context);
        this.items = items;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) 
    {
    	View view = convertView;
        if (view == null) 
        {
        	view = this.inflater.inflate(R.layout.favorite_liste_item, null);
        }
        Element element = items.get(position);
        TextView name = (TextView) view.findViewById(R.id.favorite_list_item_text);
          
        if (element != null && name != null) 
        {
        	name.setText(element.getName());
        }
        return view;
    }
}
